﻿using Dapper;
using HR.Filters;
using HR.IServices.PengIService;
using HR.Models.PengModels;
using Microsoft.AspNetCore.Mvc;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;

namespace HR.Controllers
{
    public class JianLiGuanLiController : Controller
    {
        private readonly IJianLiGuanLiServices jianLiGuanLiServices;
        private readonly ILogger<JianLiGuanLiController> logger;

        public JianLiGuanLiController(IJianLiGuanLiServices jianLiGuanLiServices, ILogger<JianLiGuanLiController> logger)
        {
            this.jianLiGuanLiServices = jianLiGuanLiServices;
            this.logger = logger;
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult Index()
        {
            return View();
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult LYSPIndex() {
            return View();
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        public IActionResult LYSelIndex() {
            return View();
        }
        //简历登记  添加  职位分类 职位名称合并
        public IActionResult HeBing()
        {
            //获取职位分类数据
            string sql = @"select major_kind_id as id,major_kind_name as name from config_major_kind";
            SqlConnection con = new SqlConnection(@"Data Source=.;Initial Catalog=HR_DB;Integrated Security=True");
            List<DZhiweiFenLei> list = con.Query<DZhiweiFenLei>(sql).ToList();
            foreach(DZhiweiFenLei item in list)
            {
                //获取二级数据
                string sql2 = $@"select major_id as id,major_name as name from config_major where major_kind_id={item.id}";
                item.children = con.Query<DZhiWeiName>(sql2).ToList();
            }
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> GuoJi() 
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.GuoJi();
            return Json(list);
        }
        [HttpPost]
        public async Task<IActionResult> Insert([FromBody] JianLiGuanLi jianLiGuanLi) 
        {
            int result = await jianLiGuanLiServices.Add(jianLiGuanLi);
            if (result > 0)
            {
                return Content(result.ToString());
            }
            else 
            {
                return View(result);
            }
        }
        [HttpPost]
        public async Task<IActionResult> UpdZt([FromBody] JianLiGuanLi jianLiGuanLi) {
            int result = await jianLiGuanLiServices.UpdZt(jianLiGuanLi);
            if (result > 0)
            {
                return Content(result.ToString());
            }
            else {
                return View(result);
            }
        }
        [HttpPost]
        public async Task<IActionResult> UPDMianShics([FromBody] MianShi ms)
        {
            int result = await jianLiGuanLiServices.UPDMianShics(ms);
            if (result > 0)
            {
                return Content(result.ToString());
            }
            else
            {
                return View(result);
            }
        }
        [HttpPost]
        public async Task<IActionResult> UPDCheckst([FromBody] JianLiGuanLi jianLiGuanLi)
        {
            int result = await jianLiGuanLiServices.UpdCheckstu(jianLiGuanLi);
            if (result > 0)
            {
                return Content(result.ToString());
            }
            else
            {
                return Json(result);
            }
        }
        [HttpPost]
        public async Task<IActionResult> UPDChecksts([FromBody] JianLiGuanLi jianLiGuanLi) {
            int result = await jianLiGuanLiServices.UpdCheckstus(jianLiGuanLi);
            if (result > 0)
            {
                return Content(result.ToString());
            }
            else
            {
                return Json(result);
            }
        }
        [HttpGet]
        public async Task<IActionResult> MsJlSel()
        {
            List<MsJlLianCha> list = await jianLiGuanLiServices.msJlLians();
            return Json(list);
        }
        //查询check状态为3的
        [HttpGet]
        public async Task<IActionResult> MsJlSels() {
            List<MsJlLianCha> list = await jianLiGuanLiServices.msJlLianss();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> SelLuYonJL() {
            List<JianLiGuanLi> list = await jianLiGuanLiServices.SelLuYonJL();
            return Json(list);
        }


        [HttpGet]
        public async Task<IActionResult> MinZu()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.MinZu();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> ZongJiao()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.ZongJiao();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> ZhengZhiMianMao()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.ZhengZhiMianMao();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> XueLi()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.XueLi();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> ZhuanYe()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.ZhuanYe();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> JiaoYuNianXian()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.JiaoYuNianXian();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> TeChang()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.TeChang();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> AiHao()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.AiHao();
            return Json(list);
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        //简历筛选
        public IActionResult ShaiXuan() 
        {
            return View();
        }
        //简历筛选  条件查询
        [HttpGet]
        public async Task<IActionResult> TiaoJian(string? type,string? name,string? fourName,string? time1,string? time2) 
        {
            List<JianLiGuanLi> list = await jianLiGuanLiServices.TiaoJian(type,name,fourName,time1,time2);
            return Json(list);
        }
        //查询全部
        [HttpGet]
        public async Task<IActionResult> SelAllJl() {
            List<JianLiGuanLi> list = await jianLiGuanLiServices.SelAllJl();
            return Json(list);
        }
        //简历筛选 修改
        [HttpPut]
        public async Task<IActionResult> UpdateTwo([FromBody] JianLiGuanLi jianLiGuanLi) 
        {
            int result = await jianLiGuanLiServices.UpdateTwo(jianLiGuanLi);
            if (result > 0)
            {
                return Content(result.ToString());
            }
            else 
            {
                return View(jianLiGuanLi);
            }
        }
        [TypeFilter(typeof(RoleFilterAttribute))]
        //有效简历
        public IActionResult YouXiao() 
        {
            return View();
        }
        //有效查询
        public async Task<IActionResult> YouXiaoFind(string? type, string? name, string? fourName, string? time1, string? time2) 
        {
			List<JianLiGuanLi> list = await jianLiGuanLiServices.YouXiao(type, name, fourName, time1, time2);
			return Json(list);
		}
        //有效查询简历状态为1的
        [HttpGet]
        public async Task<IActionResult> SelYouX() {
            List<MsJlLianCha> list = await jianLiGuanLiServices.SelYouX();
            return Json(list);
        }
        [HttpGet]
        public async Task<IActionResult> ZhiCheng()
        {
            List<GongGongShuXing> list = await jianLiGuanLiServices.ZhiCheng();
            return Json(list);
        }
        [HttpPost]
        public IActionResult te()
        {
            MailMessage mailMsg = new MailMessage();//两个类，别混了，要引入System.Net这个Assembly
            mailMsg.From = new MailAddress("3099558075@qq.com");//源邮件地址 
            mailMsg.To.Add(new MailAddress("1760708378@qq.com"));//目的邮件地址。可以有多个收件人
            mailMsg.Subject = "录用申请";//发送邮件的标题 
            mailMsg.Body = "您好!恭喜您被录用。" + DateTime.Now;//发送邮件的内容 
            SmtpClient client = new SmtpClient("smtp.qq.com");//smtp.163.com，smtp.qq.com
            client.Credentials = new NetworkCredential("3099558075@qq.com", "lgasjlxtpmapdeif");
            client.Send(mailMsg);
            return Json(client);
        }
    }
}
